/**
 * Created by Zhouxiumin on 2017/3/28.
 */

import {BaseParser} from './BaseParser'
import {SosoParser} from './SosoParser'
import {TwoMangaParser} from './twomangaparser'


function findEngine(){

  let foundParser:BaseParser;
  let engines:Array<BaseParser> = [];
  let baseParser = new BaseParser();
  let sosoParser = new SosoParser();
  engines.push(sosoParser);
  let twoMangaParser = new TwoMangaParser();
  engines.push(twoMangaParser);

  let parserFound = false;
  for(let i=0;i<engines.length;i++){
    let parser = engines[i];
    if(new RegExp(parser.getExpr()).test(window.location.href)){
      foundParser = parser;
      parserFound = true;
    }
  }
  if(!parserFound){
    foundParser = baseParser;
  }
  return foundParser;
}

export const parser = findEngine();
